package com.coderush.admin.sys.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coderush.admin.sys.mapper.JobMapper;
import com.coderush.admin.sys.model.entity.Company;
import com.coderush.admin.sys.model.entity.Job;
import com.coderush.admin.sys.model.vo.JobPageVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Repository;

/**
 * PackageName com.coderush.admin.sys.dao
 *
 * @Author Eason
 * @Version v1.0
 * @ClassName JobDao
 * @Date 2025/8/27
 * @Description TODO
 */
@Repository
public class JobDao {

    @Resource
    private JobMapper jobMapper;

    /**
     * 分页查询
     */
    public Page<JobPageVo> findByPage(Page<JobPageVo> page, String jobName) {
        return jobMapper.findByPage(page, jobName);
    }

    /**
     * 根据公司ID、部门ID、职位编码 查询职位
     */
    public Job getByCompanyIdAndDeptId(Long companyId, Long departmentId, String jobCode) {
        return jobMapper.findByCompanyIdAndDeptId(companyId, departmentId, jobCode);
    }
    /**
     * 根据公司ID、部门ID、职位名称 查询职位
     */
    public Job getByCompanyIdAndDeptIdAndJobName(Long companyId, Long departmentId, String jobName) {
        return jobMapper.findByCompanyIdAndDeptIdAndJobName(companyId, departmentId, jobName);
    }

    /**
     * 添加职位
     */
    public Boolean add(Job job) {
        return jobMapper.insert(job) > 0;
    }

    /**
     * 根据ID查询职位
     * @param id
     * @return
     */
    public Job getById(Long id) {
        return jobMapper.selectById(id);
    }

    /**
     * 修改职位
     */
    public Boolean update(Job job) {
        return jobMapper.updateById(job) > 0;
    }
}